﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactListControl.ascx.cs" Inherits="User_Controls_ContactListControl" %>
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
    <asp:View ID="MainView" runat="server">
    <h2>联系人列表</h2>
        <asp:GridView ID="ContactListGridView" runat="server" AutoGenerateColumns="False" 
        CssClass="normal" DataSourceID="ContactsDataSource" DataKeyNames="Id" OnSelectedIndexChanged="ContactListGridView_SelectedIndexChanged">
            <Columns>
                <asp:CommandField ShowSelectButton="True" SelectText="编辑" />
                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                            CommandName="Delete" OnClientClick="return deleteConfirm(event);"
                            Text="删除"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Name" HeaderText="姓名" SortExpression="Name" />
                <asp:TemplateField HeaderText="电话" SortExpression="Tel">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" 
                        Text='<%# Eval("Tel") == null ? string.Empty : Eval("Tel").ToString().Replace(Environment.NewLine, "<br />") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="手机" SortExpression="Mobile">
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" 
                        Text='<%# Eval("Mobile") == null ? string.Empty : Eval("Mobile").ToString().Replace(Environment.NewLine, "<br />")  %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Position" HeaderText="职位" SortExpression="Position" />
                <asp:BoundField DataField="QQ" HeaderText="QQ" SortExpression="QQ" />
                <asp:BoundField DataField="MSN" HeaderText="MSN" SortExpression="MSN" />
                <asp:BoundField DataField="Description" HeaderText="备注" SortExpression="Description" />
            </Columns>
            <EmptyDataTemplate>
                暂无联系人信息.
            </EmptyDataTemplate>
        </asp:GridView>
        <p>
            <asp:LinkButton ID="lbtnAddContact" runat="server" OnClick="lbtnAddContact_Click">添加联系人</asp:LinkButton></p>
        <csla:CslaDataSource ID="ContactsDataSource" runat="server" 
            TypeName="Active.Core.Contacts, Active.Core" OnSelectObject="ContactsDataSource_SelectObject"
            TypeSupportsPaging="False" TypeSupportsSorting="False" OnDeleteObject="ContactsDataSource_DeleteObject"></csla:CslaDataSource>
    </asp:View>
    <asp:View ID="EditContactView" runat="server">
    <p><asp:LinkButton ID="lbtnReturn" runat="server" CausesValidation="false" OnClick="lbtnReturn_Click">返 回</asp:LinkButton></p>
     <h2>联系人信息</h2>
        <asp:DetailsView ID="ContactDetailsView" runat="server" AutoGenerateRows="False" 
            DataSourceID="ContactDataSource" DataKeyNames="Id">
            <Fields>
                <asp:TemplateField HeaderText="姓名" SortExpression="Name">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ControlToValidate="txtName"
                            ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ControlToValidate="txtName"
                            ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="电话" SortExpression="Tel">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" TextMode="MultiLine" Rows="3" runat="server" Text='<%# Bind("Tel") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox2" TextMode="MultiLine" Rows="3" runat="server" Text='<%# Bind("Tel") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("Tel") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="手机" SortExpression="Mobile">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox3" TextMode="MultiLine" Rows="3" runat="server" Text='<%# Bind("Mobile") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox3" TextMode="MultiLine" Rows="3" runat="server" Text='<%# Bind("Mobile") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("Mobile") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Position" HeaderText="职位" SortExpression="Position" />
                <asp:BoundField DataField="QQ" HeaderText="QQ" SortExpression="QQ" />
                <asp:BoundField DataField="MSN" HeaderText="MSN" SortExpression="MSN" />
                <asp:TemplateField HeaderText="备注" SortExpression="Description">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" TextMode="MultiLine" Rows="3" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox1" TextMode="MultiLine" Rows="3" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowEditButton="True" InsertText="添加" UpdateText="保存" 
                    ShowInsertButton="True" />
            </Fields>
        </asp:DetailsView>
        <csla:CslaDataSource ID="ContactDataSource" runat="server" 
            TypeName="Active.Core.Contact, Active.Core"
            OnInsertObject="ContactDataSource_InsertObject" OnSelectObject="ContactDataSource_SelectObject"
            OnUpdateObject="ContactDataSource_UpdateObject" 
            TypeSupportsPaging="False" TypeSupportsSorting="False">
         </csla:CslaDataSource>
    </asp:View>
</asp:MultiView>